package net.wanho.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import net.wanho.entity.Student;
import net.wanho.service.StudentService;
import net.wanho.vo.AjaxResult;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * Author：汤小洋
 * Date：2025-06-30 9:42
 * Description：<描述>
 */
@Api(tags = "01.学生模块")
@RestController
@RequestMapping("/students")
@RequiredArgsConstructor
public class StudentController {

    private final StudentService studentService;

    @ApiOperation("用户列表")
    @GetMapping
    public AjaxResult list(){
        List<Student> list = new ArrayList<>();
        list.add(new Student("小王", "12345678901", "北京"));
        list.add(new Student("小张", "12345678902", "上海"));
        list.add(new Student("小李", "12345678903", "广州"));
        return AjaxResult.success(list);
    }

    @ApiOperation("/根据id查询用户")
    @GetMapping("/{id}")
    public AjaxResult findById(@ApiParam("用户id") @PathVariable int id){
        return AjaxResult.success(new Student("小王", "12345678901", "北京"));
    }

    @ApiOperation("/添加用户")
    @PostMapping
    public AjaxResult add(@ApiParam("要添加的用户信息") @RequestBody Student stu){
        studentService.add(stu);
        return AjaxResult.success("添加学生成功");
    }

    @ApiOperation("修改用户")
    @PutMapping
    public AjaxResult modify(@RequestBody Student stu){
        System.out.println(stu);
        return AjaxResult.success("修改学生成功");
    }

    @ApiOperation("根据id删除用户")
    @DeleteMapping("/{id}")
    public AjaxResult removeById(@PathVariable int id){
        System.out.println(id);
        return AjaxResult.success("删除学生成功");
    }

}
